package com.wngz.activity.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("异步响应结果")
public class ResponseResult<T> {
    //处理的错误码，当错误码为200时，表示处理成功，其他编码一律表示失败，不同的错误有不同的编码
    @ApiModelProperty("错误码")
    private String code;
    @ApiModelProperty("错误描述")
    private String errorMsg; //错误的原因
    @ApiModelProperty("正常响应数据")
    private T data; //如果没有错误，将正常返回的数据


    public static <T> ResponseResult success(T data){
        ResponseResult responseResult = new ResponseResult();
        responseResult.code = "200";
        responseResult.data = data;

        return responseResult;
    }

    public static <T> ResponseResult success(){
        ResponseResult responseResult = success(null);

        return responseResult;
    }

    public static <T> ResponseResult failure(String code,String errorMsg){
        ResponseResult responseResult = new ResponseResult();
        responseResult.code = code;
        responseResult.errorMsg = errorMsg;

        return responseResult;
    }

    public static <T> ResponseResult failure(String errorMsg){
        ResponseResult responseResult = failure("500",errorMsg);

        return responseResult;
    }
}
